function loadSectionDataSources() {

  //load preferences
  var prefs = new gadgets.Prefs();

  var course_code = prefs.getString("course_code");

  var temp = prefs.getString("section_data_source");
  
  var section_data_source = new Array();
  
  var i = 0;

  for(i = 0; i < temp.length; i+=2) {
    section_data_source[temp[i]] = temp[i+1];
  }

  //prepare dropdown
  var select_section = document.getElementById('section');

  select_section.options.length = 0;

  for(var index in section_data_source) {
    select_section.options[select_section.options.length] = new Option(index, section_data_source[index]);
  }
}

function drawVisualization() {

  //get ID number
  var id_num = document.getElementById('id_num').value;

  if(id_num == '') {
    document.getElementById('content-div').innerHTML = 'Empty ID Number';
    return;
  }  

  //show spinner
  document.getElementById('content-div').innerHTML = '<img src="https://www.google.com/ig/images/spinner.gif" />';  

  var prefs = new gadgets.Prefs();

  //load columns and labels
  var temp = prefs.getString("column_label");

  var column_label = new Array();

  var i = 0;

  for(i = 0; i < temp.length; i+=2) {
    column_label[temp[i]] = temp[i+1];
  }

  //prepare query
  var query = select_list.options[select_list.selectedIndex].value;

  var query_string = 'SELECT ';

  i = 0;
  for(var index in column_label) {
    query_string = query_string.concat(index);
    i++;
    if(i < column_label.length)
      query_string = query_string.concat(', ');
    else
      query_string = query_string.concat(' ');      
  }

  query_string = query_string.concat('WHERE A = ' + id_num);

  query_string.setQuery(query_string);

  query_string.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    document.getElementById('title-div').innerHTML = '';        
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }  

  var data = response.getDataTable();
  
  if(data.getNumberOfRows() == 0) {
    document.getElementById('content-div').innerHTML = 'No data found';
    return;
  }

  var prefs = new gadgets.Prefs();

  //load columns and labels
  var temp = prefs.getString("column_label");

  var column_label = new Array();

  var i = 0;

  for(i = 0; i < temp.length; i+=2) {
    column_label[i] = temp[i+1];
  }

  var row_wise_data = new google.visualization.DataTable();
  row_wise_data.addColumn('string', 'CRITERIA');
  row_wise_data.addColumn('string', 'VALUE');
  
  var i = 0;
  
  for(i =  0; i < data.getNumberOfColumns(); i++) {    
    row_wise_data.addRow(['' + column_label[i], '' + data.getValue(0, i)]);
  }

  visualization = new google.visualization.Table(document.getElementById('content-div'));
  visualization.draw(row_wise_data, null);
}

/*
function drawVisualization() {
  //alert('In drawVisualization');

  google.load("visualization", "1", {"packages": ["table"]});        

  var prefs = new gadgets.Prefs();

  var select_list = document.getElementById('section');

  var section_data_source = select_list.options[select_list.selectedIndex].text;

  //alert(prefs.getString(section_data_source));

  var query = new google.visualization.Query(prefs.getString(section_data_source));

  var id_num = document.getElementById('id_num').value;

  if(id_num == '') {
    document.getElementById('content-div').innerHTML = 'Empty ID Number';
    return;
  }

  document.getElementById('content-div').innerHTML = '<img src="https://www.google.com/ig/images/spinner.gif" />';

  //alert(id_num);
  
  var query_string = 'SELECT A, B, K, N, O, P, S, T, V, W, X, Y, Z, AA, AB, AC, AD, AE, AF, AG, AH, AI, AJ WHERE A = ' + id_num;
  
  query.setQuery(query_string);

  document.getElementById('title-div').innerHTML = 'OBJECTP grade for student ' + id_num;

  query.send(handleQueryResponse);
}

function

function handleQueryResponse(response) {
  if (response.isError()) {
    document.getElementById('title-div').innerHTML = '';        
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }  

  var data = response.getDataTable();
  
  if(data.getNumberOfRows() == 0) {
    document.getElementById('content-div').innerHTML = 'No data found';
    return;
  }

  var row_wise_data = new google.visualization.DataTable();
  row_wise_data.addColumn('string', 'CRITERIA');
  row_wise_data.addColumn('string', 'VALUE');
  
  var i = 0;
  
  for(i =  0; i < data.getNumberOfColumns(); i++) {    
    row_wise_data.addRow(['' + data.getColumnLabel(i), '' + data.getValue(0, i)]);
  }

  visualization = new google.visualization.Table(document.getElementById('content-div'));
  visualization.draw(row_wise_data, null);
}
*/